/*
 * CDamageStats.java
 *
 * Copyright (c) 2009 Giles Millward (Manigra). All rights reserved.
 *
 * This file is part of JRogueDPS.
 *
 * JRogueDPS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JRogueDPS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JRogueDPS.  If not, see <http://www.gnu.org/licenses/>.
 */

package dpsstats;

import dpssystem.CAttackChance.HitType;
import java.util.ArrayList;

/**
 *
 * @author gmillward
 */
public class CDamageStats {
    private String m_name;
    private CDamageType m_normal;
    private CDamageType m_miss;
    private CDamageType m_dodge;
    private CDamageType m_crit;
    private CDamageType m_glancing;
    private CDamageType m_resist;
    private ArrayList<CDamageType> m_array = new ArrayList<CDamageType>();

    public CDamageStats (String p_name)
    {
        m_name = p_name;
        initStats();
    }

    public CDamageStats()
    {
        initStats();
        m_name = "";
    }

    private void initStats()
    {
        m_normal = new CDamageType();
        m_miss = new CDamageType();
        m_dodge = new CDamageType();
        m_crit = new CDamageType();
        m_glancing = new CDamageType();
        m_resist = new CDamageType();
        m_array.add(m_normal);
        m_array.add(m_miss);
        m_array.add(m_dodge);
        m_array.add(m_crit);
        m_array.add(m_glancing);
        m_array.add(m_resist);
    }

    public void setName(String p_name)
    {
        m_name = p_name;
    }

    public String getName()
    {
        return m_name;
    }

    public void resetStats()
    {
        for (int i = 0; i < m_array.size(); i++)
        {
            m_array.get(i).reset();
        }
    }

    public void add(CDamageStats p_damageStats)
    {
        for (int i = 0; i < this.m_array.size(); i++)
        {
            m_array.get(i).add(p_damageStats.m_array.get(i));
        }

        this.m_name = p_damageStats.getName();
    }

    public void divideBy(int p_divisor)
    {
        for (int i = 0; i < this.m_array.size(); i++)
        {
            m_array.get(i).divideBy(p_divisor);
        }
    }
    
    public void addStats(HitType p_hitType, double p_damage)
    {
        if (p_hitType == HitType.NORMAL)
        {
            m_normal.addDamage(p_damage);
        } else if (p_hitType == HitType.CRIT)
        {
            m_crit.addDamage(p_damage);
        } else if (p_hitType == HitType.MISS)
        {
            m_miss.addCount();
        } else if (p_hitType == HitType.DODGE)
        {
            m_dodge.addCount();
        } else if (p_hitType == HitType.GLANCING)
        {
            m_glancing.addDamage(p_damage);
        } else if (p_hitType == HitType.RESIST)
        {
            m_resist.addDamage(p_damage);
        } 
    }

    public CDamageType getStats(HitType p_hitType)
    {
        if (p_hitType == HitType.NORMAL)
        {
            return m_normal;
        } else if (p_hitType == HitType.CRIT)
        {
            return m_crit;
        } else if (p_hitType == HitType.MISS)
        {
            return m_miss;
        } else if (p_hitType == HitType.DODGE)
        {
            return m_dodge;
        } else if (p_hitType == HitType.GLANCING)
        {
            return m_glancing;
        } else if (p_hitType == HitType.RESIST)
        {
            return m_resist;
        }

        return null;
    }

    public double getTotalDamage()
    {
        return (m_normal.getDamage() + m_crit.getDamage() +
                m_glancing.getDamage() + m_resist.getDamage());
    }

    public int getTotalCount()
    {
        int l_count = 0;
        for (int i = 0; i < this.m_array.size(); i++)
        {
            l_count += m_array.get(i).getCount();
        }

        return l_count;
    }
}
